using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.ComponentModel;

namespace Enterprise_Store
{
    public partial class MainWindow : Window
    {

        DataBinding controler;

        public MainWindow(DataBinding control)
        {
            InitializeComponent();
            controler = control;

            if (controler.CurrentApp == null)
            {
                controler.CurrentApp = new AppPackage();
                Binding bindDetail = new Binding();
                bindDetail.Source = controler.CurrentApp;
                Detail.SetBinding(ContentControl.ContentProperty, bindDetail);
            }

            Binding bind = new Binding();
            bind.Source = controler.CurrentApp.Xml;
            xml.SetBinding(TextBlock.TextProperty, bind);

            /*XmlDataProvider w8csxml = new XmlDataProvider();
            w8csxml.Source = new Uri(@"c:\temp\testapp.xml");*/
            //xmlFile.DataContext = w8csxml;
        }


        private void copyToClipboard(object sender, RoutedEventArgs e)
        {
            System.Windows.Clipboard.SetText(controler.CurrentApp.Xml);
        }


        private void saveToFile(object sender, RoutedEventArgs e)
        {
            //AddProductWindow addProductWindow = new AddProductWindow();
            //addProductWindow.ShowDialog();
        }

        private void EditFromW8CSConf(object sender, RoutedEventArgs e)
        {

        }


        private void AddToW8CSConf(object sender, RoutedEventArgs e)
        {
            
            if (controler.CurrentApp == null)
            {
                controler.CurrentApp = new AppPackage();
                Binding bindDetail = new Binding();
                bindDetail.Source = controler.CurrentApp;
                Detail.SetBinding(ContentControl.ContentProperty, bindDetail);
            }

            Binding bind = new Binding();
            bind.Source = controler.CurrentApp.Xml;
            xml.SetBinding(TextBlock.TextProperty,bind);
        }

        private void EditInstalledApp(object sender, RoutedEventArgs e)
        {
            controler.CurrentApp = (AppPackage)Master.SelectedItem;
            Binding bind = new Binding();
            bind.Source = controler.CurrentApp;
            Detail.SetBinding(ContentControl.ContentProperty, bind);
            
        }

        
    }
}